import urllib2
import time

class Speedproxytester(object):
    """Este modulo es para identificar la velocidad de un proxy que este funcionando
"""
    def  __init__(self,proxy = "",site = "http://google.com.pa"):
        self.proxy = proxy
        self.site = site
        self.builder(self.proxy)
        
    def builder(self,proxy):
        'Crea un opener con el proxy predeterminado'
        proxy = proxy.split(":")
        proxy_support = urllib2.ProxyHandler({"http" : "%s:%d" % (proxy[0], int(proxy[1]))})
        opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
        opener.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')]
        urllib2.install_opener(opener)
        self.cheker()
    def cheker(self):
        'Revisa el proxy que abra la pagina'
        time1  = time.time()
        try:
            source = urllib2.urlopen(self.site).read(2048)
            time2  = time.time()
        except:
            source = ''
        if source == '':
            print "[!] Hubo un problema con el proxy"
        else:
            tDiff = (time2-time1)
            print "Speed : "+("%.2f" % round(2048/(tDiff*1000),2))+"kB/s"
